def cfg_groups_test_1():
  CfgPlaceGroup1.AddPlace(CfgPlace1)
  CfgAgentGroup1.AddAgent(CfgAgent1)
  CfgAgentGroup2 = CfgAgentGroup()
  groupInfo = CfgGroup()
  groupInfo .SetAttributes({"tenantDBID": CfgTenant1.DBID, "name": "AgentGroup2"})
  CfgAgentGroup2.groupInfo = groupInfo 
  CfgAgentGroup2.Add()
  CfgAgentGroup2.AddAgent(CfgAgent1)
  CfgAgentGroup2.DeleteAgent(CfgAgent1)
  CfgAgentGroup2.Delete()
  CfgPlaceGroup1.DeletePlace(CfgPlace1)
  CfgAgentGroup1.DeleteAgent(CfgAgent1)

def add_delete_solution_components_1():
  CfgSolutionOutbound.AddComponent(CfgLocalTserver)
  raw_input()
  CfgSolutionOutbound.DeleteComponent(CfgLocalTserver)
  
  CfgSolutionOutbound.AddComponent(CfgLocalTserver, 3, CfgFlag.True)
  raw_input()
  CfgSolutionOutbound.DeleteComponent(CfgLocalTserver)

def change_redundancy_type_1():
  CfgLocalTserver.SetRedundancyType(CfgHAType.CFGHTHotStanby)

def change_options_1():
  CfgLocalTserver.AddOption("Simulator", "key1", "value1")
  CfgLocalTserverBackup.ChangeOption("Simulator", "key1", "value2")
  CfgLocalTserver.DeleteOption("Simulator", "key1")
  CfgLocalTserver.AddOption("Simulator", "key1", "value1", annex = 1)
  CfgLocalTserverBackup.ChangeOption("Simulator", "key1", "value2", annex = 1)
  CfgLocalTserver.DeleteOption("Simulator", "key1", annex = 1)
  


def change_annex_1():
  CfgSwitchG3_link6.AddOption("Simulator", "key1", "value1", annex = 1)
  CfgSwitchG3_link6.ChangeOption("Simulator", "key1", "value2", annex = 1)
  CfgSwitchG3_link6.DeleteOption("Simulator", "key1", annex = 1)

def treatments_and_filters():
  print CfgTreatment1.callResult
  print ValToEnumElem(CallState, CfgTreatment1.callResult)
  print "*****************"
  CfgFilter1.ChangeOption("default", "criteria", "value1", annex = 1)
  CfgFilter1.ChangeOption("default", "order_by", "value2", annex = 1)

def change_access_code_1():
  CfgSwitch1.ChangeAccessCode(CfgSwitch2, "00")

def change_time_treatment_1():
  CfgTreatment1.ChangeDateTime(time.time() + 60*60) # now + 1 hour

def change_host_port():
  SetSaveConfigurationChanges(True)
  CfgLocalTserver.ChangeHost("NonExistingHost")
  CfgLocalTserver.ChangePort("3333")
  raw_input("Check changes. Press enter")

def change_host_port_back():
  SetSaveConfigurationChanges(True)
  CfgLocalTserver.ChangeHost("mashaf1")
  CfgLocalTserver.ChangePort("6410")
  raw_input("Check changes. Press enter")


def add_delete_access_code():
  CfgSwitchG3_SIM.AddAccessCode(CfgSwitchG3_SIM1, "00555", CfgRouteType.CFGXRouteTypeDirectANI)
  raw_input("Check changes. Press enter")
  CfgSwitchG3_SIM.DeleteAccessCode(CfgSwitchG3_SIM1)
  raw_input("Check changes. Press enter")

  CfgSwitchG3_SIM.AddAccessCode(None, "2222", CfgRouteType.CFGXRouteTypeDirectANI)
  raw_input("Check changes. Press enter")
  CfgSwitchG3_SIM.DeleteAccessCode(None)
  raw_input("Check changes. Press enter")
  
def disable_enable_extroutepoint():
  CfgExtRP1.ChangeState(CfgObjectState.CFGDisabled) #disable
  raw_input("Check changes. Press enter")
  CfgExtRP1.ChangeState(CfgObjectState.CFGEnabled) #enable
  raw_input("Check changes. Press enter")
  
def assigning_default_places():
  for i in range(0,50):
    u = str(24100 + i)
    d = str(100 + i)
    ag = CfgPerson("Ag_"+ u +"_G3_SIM")
    place = CfgPlace("vcb", "Place_"+ d +"_G3_SIM")
    ag.BeginChange()
    ag.agentInfo["placeDBID"] = place.DBID
    ag.EndChange()
 
def new_tenant():
  CfgTenantNew = CfgTenant()
  CfgTenantNew.SetAttributes({"name": "nameCfgTenantNew"})
  CfgTenantNew.Add()
  CfgTenantNew.Delete()    

def new_phswitch_switch():
  CfgPhysicalSwitchNew = CfgPhysicalSwitch()
  CfgPhysicalSwitchNew.SetAttributes({"name": "namePhysicalSwitchNew", "type":CfgSwitchType.CFGLucentDefinityG3})
  CfgPhysicalSwitchNew.Add()
  CfgSwitchNew = CfgSwitch()
  CfgSwitchNew.SetAttributes({"name": "nameCfgSwitchNew ", "physSwitchDBID":CfgPhysicalSwitchNew .DBID, "tenantDBID":CfgTenant1.DBID})
  CfgSwitchNew.Add()
  CfgSwitchNew.Delete()  
  CfgPhysicalSwitchNew .Delete()  
  
def new_DN():

  CfgDNNew = CfgDN()
  CfgDNNew.SetAttributes({"number": "24508", "tenantDBID":CfgTenant1.DBID, "switchDBID":CfgSwitch1.DBID, "type": CfgDNType.CFGExtension.val})
  CfgDNNew.Add()
  CfgDNNew.Delete()


def new_person():
  CfgPersonNew = CfgPerson()
  CfgPersonNew .SetAttributes({"employeeID": "employeeIDCfgPersonNew", "tenantDBID":CfgTenant1.DBID, "userName": "userNameCfgPersonNew"})
  CfgPersonNew.Add()
  CfgPersonNew.Delete()

def new_skill_agentlogin():
  CfgSkillNew = CfgSkill()
  CfgSkillNew.SetAttributes({"name": "nameCfgSkillNew", "tenantDBID":CfgTenant1.DBID})
  CfgSkillNew.Add()
  CfgSkillNew.Delete()

  CfgAgentLoginNew = CfgAgentLogin()
  CfgAgentLoginNew.SetAttributes({"loginCode": "loginCodeCfgAgentLoginNew ", "tenantDBID":CfgTenant1.DBID, "switchDBID":CfgSwitch1.DBID})
  CfgAgentLoginNew.Add()
  CfgAgentLoginNew.Delete()
  
  
def NEW_CONFIGURATION_1():
  """Much easier than wizards!!!"""
  #--------------------------------------
  TenantName = "PythonTenant"
  #--------------------------------------

  SwitchType1 = CfgSwitchType.CFGLucentDefinityG3
  SwitchName1 = "PythonSwitchG3MAPD_LINK1"
  Exensions1 = ["24500", "24501", "24502"]
  Positions1 = []
  ACDQueues1 = ["24183", "24193"] # will be configured as ACD splits
  RoutingPoints1 = ["24304", "24305", "24201"]# will be configured as RouteDNs
  RoutingQueues1 = []# will be configured as RouteQueues
  AgentLogins1 = ["24004", "24005"]
  
  ExternalRoutingPoints1 = ["24204"]
  AccessCode1 = "8323"
  TserverName1 = "TS-G3MAPD-LINK1" # Tserver must be configured already
  #--------------------------------------

  SwitchType2 = CfgSwitchType.CFGLucentDefinityG3
  SwitchName2 = "PythonSwitchCERTG3_LINK1"
  Exensions2 = ["4131", "4132"]
  Positions2 = []
  ACDQueues2 = [] # will be configured as ACD splits
  RoutingPoints2 = []# will be configured as RouteDNs
  RoutingQueues2 = []# will be configured as RouteQueues
  AgentLogins2 = []  
  
  ExternalRoutingPoints2 = ["4505"]
  AccessCode2 = "8320"
  TserverName2 = "TS-CERTG3-LINK1" #Tserver must be configured already
  #--------------------------------------

  CfgTenantNew = CfgTenant()
  CfgTenantNew.SetAttributes({"name": TenantName})
  CfgTenantNew.Add()
  CfgPhysicalSwitchNew1 = CfgPhysicalSwitch()
  CfgPhysicalSwitchNew1.SetAttributes({"name": str(SwitchType1) + "_1", "type":SwitchType1})
  CfgPhysicalSwitchNew1.Add()
  CfgSwitchNew1 = CfgSwitch()
  CfgSwitchNew1.SetAttributes({"name": SwitchName1, "physSwitchDBID":CfgPhysicalSwitchNew1.DBID, "tenantDBID":CfgTenantNew.DBID})
  CfgSwitchNew1.Add()
  for dnName in Exensions1:
    CfgDNNew = CfgDN()
    CfgDNNew.SetAttributes({"number": dnName, "tenantDBID":CfgTenantNew.DBID, "switchDBID":CfgSwitchNew1.DBID, "type": CfgDNType.CFGExtension})
    CfgDNNew.Add()

  for dnName in Positions1:
    CfgDNNew = CfgDN()
    CfgDNNew.SetAttributes({"number": dnName, "tenantDBID":CfgTenantNew.DBID, "switchDBID":CfgSwitchNew1.DBID, "type": CfgDNType.CFGPosition})
    CfgDNNew.Add()  

  for dnName in ACDQueues1:
    CfgDNNew = CfgDN()
    CfgDNNew.SetAttributes({"number": dnName, "tenantDBID":CfgTenantNew.DBID, "switchDBID":CfgSwitchNew1.DBID, "type": CfgDNType.CFGACDQueue})
    CfgDNNew.Add()    

  for dnName in RoutingPoints1:
    CfgDNNew = CfgDN()
    CfgDNNew.SetAttributes({"number": dnName, "tenantDBID":CfgTenantNew.DBID, "switchDBID":CfgSwitchNew1.DBID, "type": CfgDNType.CFGRoutingPoint})
    CfgDNNew.Add() 

  for dnName in RoutingQueues1:
    CfgDNNew = CfgDN()
    CfgDNNew.SetAttributes({"number": dnName, "tenantDBID":CfgTenantNew.DBID, "switchDBID":CfgSwitchNew1.DBID, "type": CfgDNType.CFGRoutingQueue})
    CfgDNNew.Add() 

  for dnName in ExternalRoutingPoints1:
    CfgDNNew = CfgDN()
    CfgDNNew.SetAttributes({"number": dnName, "tenantDBID":CfgTenantNew.DBID, "switchDBID":CfgSwitchNew1.DBID, "type": CfgDNType.CFGExtRoutingPoint})
    CfgDNNew.Add()
    
  for loginCode in AgentLogins1:
    CfgAgentLoginNew = CfgAgentLogin()
    CfgAgentLoginNew.SetAttributes({"loginCode": loginCode, "tenantDBID":CfgTenantNew.DBID, "switchDBID":CfgSwitchNew1.DBID})
    CfgAgentLoginNew.Add()  
    
  CfgApplication1 = CfgApplication(TserverName1)

  CfgSwitchNew1.ChangeTserver(CfgApplication1)
 
    
  #--------------------------  
  CfgPhysicalSwitchNew2 = CfgPhysicalSwitch()
  CfgPhysicalSwitchNew2.SetAttributes({"name": str(SwitchType2) + "_2", "type":SwitchType2})
  CfgPhysicalSwitchNew2.Add()
  CfgSwitchNew2 = CfgSwitch()
  CfgSwitchNew2.SetAttributes({"name": SwitchName2, "physSwitchDBID":CfgPhysicalSwitchNew2.DBID, "tenantDBID":CfgTenantNew.DBID})
  CfgSwitchNew2.Add()
  for dnName in Exensions2:
    CfgDNNew = CfgDN()
    CfgDNNew.SetAttributes({"number": dnName, "tenantDBID":CfgTenantNew.DBID, "switchDBID":CfgSwitchNew2.DBID, "type": CfgDNType.CFGExtension})
    CfgDNNew.Add()

  for dnName in Positions2:
    CfgDNNew = CfgDN()
    CfgDNNew.SetAttributes({"number": dnName, "tenantDBID":CfgTenantNew.DBID, "switchDBID":CfgSwitchNew2.DBID, "type": CfgDNType.CFGPosition})
    CfgDNNew.Add()  

  for dnName in ACDQueues2:
    CfgDNNew = CfgDN()
    CfgDNNew.SetAttributes({"number": dnName, "tenantDBID":CfgTenantNew.DBID, "switchDBID":CfgSwitchNew2.DBID, "type": CfgDNType.CFGACDQueue})
    CfgDNNew.Add()    

  for dnName in RoutingPoints2:
    CfgDNNew = CfgDN()
    CfgDNNew.SetAttributes({"number": dnName, "tenantDBID":CfgTenantNew.DBID, "switchDBID":CfgSwitchNew2.DBID, "type": CfgDNType.CFGRoutingPoint})
    CfgDNNew.Add() 

  for dnName in RoutingQueues2:
    CfgDNNew = CfgDN()
    CfgDNNew.SetAttributes({"number": dnName, "tenantDBID":CfgTenantNew.DBID, "switchDBID":CfgSwitchNew2.DBID, "type": CfgDNType.CFGRoutingQueue})
    CfgDNNew.Add() 

  for dnName in ExternalRoutingPoints2:
    CfgDNNew = CfgDN()
    CfgDNNew.SetAttributes({"number": dnName, "tenantDBID":CfgTenantNew.DBID, "switchDBID":CfgSwitchNew2.DBID, "type": CfgDNType.CFGExtRoutingPoint})
    CfgDNNew.Add()
    


  for loginCode in AgentLogins2:
    CfgAgentLoginNew = CfgAgentLogin()
    CfgAgentLoginNew.SetAttributes({"loginCode": loginCode, "tenantDBID":CfgTenantNew.DBID, "switchDBID":CfgSwitchNew2.DBID})
    CfgAgentLoginNew.Add()      
    
  CfgApplication2 = CfgApplication(TserverName2)
  CfgSwitchNew2.ChangeTserver(CfgApplication2)
  #--------------------------
  # Connecting switches
  CfgSwitchNew1.AddAccessCode(CfgSwitchNew2, AccessCode2)
  CfgSwitchNew2.AddAccessCode(CfgSwitchNew1, AccessCode1)
  # Connecting tservers
  CfgApplication1.AddConnection(CfgApplication2)
  CfgApplication2.AddConnection(CfgApplication1)

    
  raw_input("Check created configuration. On next step it will be deleted")
  CfgTenantNew.Delete()
  CfgPhysicalSwitchNew1.Delete()
  CfgPhysicalSwitchNew2.Delete()
  

  
